#include "viml/object_pool.h"
#include <iostream>
#include <algorithm>

namespace viml {

// GlobalSimpleObjectPool实现
std::unique_ptr<SimpleObjectPoolManager> GlobalSimpleObjectPool::instance_;
std::mutex GlobalSimpleObjectPool::instance_mutex_;
bool GlobalSimpleObjectPool::initialized_ = false;

SimpleObjectPoolManager& GlobalSimpleObjectPool::get_instance() {
    std::lock_guard<std::mutex> lock(instance_mutex_);
    if (!instance_) {
        instance_ = std::make_unique<SimpleObjectPoolManager>();
        initialized_ = true;
    }
    return *instance_;
}

void GlobalSimpleObjectPool::initialize() {
    std::lock_guard<std::mutex> lock(instance_mutex_);
    if (!instance_) {
        instance_ = std::make_unique<SimpleObjectPoolManager>();
        initialized_ = true;
    }
}

void GlobalSimpleObjectPool::shutdown() {
    std::lock_guard<std::mutex> lock(instance_mutex_);
    if (instance_) {
        instance_->clear_all_pools();
        instance_.reset();
        initialized_ = false;
    }
}

bool GlobalSimpleObjectPool::is_initialized() {
    std::lock_guard<std::mutex> lock(instance_mutex_);
    return initialized_;
}

} // namespace viml